/**
 * 系统管理--用户管理的单例对象
 */
var sharesAreCompany = {
    id: "sharesAreCompanyTable",//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1,
    deptid:0
};

/**
 * 初始化表格的列
 */
sharesAreCompany.initColumn = function () {
    var columns = [
        {field: 'selectItem', radio: true},
        {title: 'id', field: 'id', visible: false, align: 'center', valign: 'middle'},
        {title: '名称', field: 'companyName', align: 'center', valign: 'middle', sortable: true, width: 100},
        {title: '电话', field: 'phone', align: 'center', valign: 'middle', sortable: true, width: 100},
        {title: '国家', field: 'country', align: 'center', valign: 'middle', sortable: true, width: 60},
        {title: '省份', field: 'province', align: 'center', valign: 'middle', sortable: true, width: 60},
        {title: '城市', field: 'cities', align: 'center', valign: 'middle', sortable: true, width: 60},
        {title: '地址', field: 'address', align: 'center', valign: 'middle', sortable: true, width: 110},
        {title: '资金', field: 'money', align: 'center', valign: 'middle', sortable: true, width: 60},
        {title: '成立时间', field: 'setupTime', align: 'center', valign: 'middle', sortable: true, width: 110},
        {title: '创建时间', field: 'createtime', align: 'center', valign: 'middle', sortable: true, width: 110},
        {title: '备注', field: 'remarks', align: 'center', valign: 'middle', sortable: true, width: 100,
            formatter: function (value, row, index) {
                return "<span title='"+value+"'>" + value + "</span>"
            },
            cellStyle: function (value, row, index) {
                return {css: {"overflow":"hidden","white-space":"nowrap","text-overflow":"ellipsis"}}
            }
        },
    ]
    return columns;
};

sharesAreCompany.search = function () {//查询预约客户列表
    sharesAreCompany.table.refresh({query: sharesAreCompany.formParams()});
};

sharesAreCompany.formParams = function () {// 查询表单提交参数对象 @returns {{}}
    var queryData = {};
    queryData['companyName'] = $("#companyName").val();
    queryData['beginTime'] = $("#beginTime").val();
    queryData['endTime'] = $("#endTime").val();
    return queryData;
};

sharesAreCompany.resetSearch = function () {
    $("#companyName").val("");
    $("#beginTime").val("");
    $("#endTime").val("");
    sharesAreCompany.search()
};

sharesAreCompany.inquire = function () {//人数统计 + 表格刷新
    sharesAreCompany.search();
};

sharesAreCompany.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if (selected.length == 0) {
        Feng.info("请先选中表格中的某一记录！");
        return false;
    } else {
        sharesAreCompany.seItem = selected[0];
        return true;
    }
};

sharesAreCompany.openAddsharesAreCompany = function () {
    var index = layer.open({
        type: 2,
        title: '添加公司信息',
        area: ['50%', '70%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/sharesAreCompany/sharesAreCompanyAdd'
    });
    this.layerIndex = index;
};

sharesAreCompany.openChangesharesAreCompany = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '编辑公司信息',
            area: ['50%', '70%'], //宽高
            fix: true, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/sharesAreCompany/sharesAreCompanyEdit/' + this.seItem.id
        });
        this.layerIndex = index;
    }
};

sharesAreCompany.delMgrsharesAreCompany = function () {
    if (this.check()) {
        var r = confirm("确认删除？")
        if (r == true) {
            var ajax = new $ax(Feng.ctxPath + "/sharesAreCompany/sharesAreCompanyDelete/" + this.seItem.id, function (data) {
                Feng.success("删除成功!");
                sharesAreCompany.table.refresh();
            }, function (data) {
                alert("没有权限，请联系系统管理员！");
                parent.layer.close(parent.layer.getFrameIndex(window.name));
            });
            ajax.start();
        } else {
        }
    }
};

sharesAreCompany.distributionSharesAreCompany = function () {  //跳到分配股份页面
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '分配股份',
            area: ['60%', '70%'], //宽高
            fix: true, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/sharesAreCompany/distributionSharesArePeople/' + this.seItem.id
        });
        this.layerIndex = index;
    }
};

$(function () {
    var defaultColunms = sharesAreCompany.initColumn();
    var table = new BSTable(sharesAreCompany.id, "/sharesAreCompany/list", defaultColunms);
    table.setPaginationType("server");
    table.setQueryParams(sharesAreCompany.formParams());
    sharesAreCompany.table = table.init();
    checkDate = function () {
        sharesAreCompany.inquire();
    };
    $(document).on('click', '#laydate_clear,#laydate_today,#laydate_ok', function () {
        sharesAreCompany.inquire();
    });
});
